#include "alertwindow.h"
#include "ui_alertwindow.h"
#include "eventshandler.h"
#include <QSound>
#include <QTimer>

AlertWindow::AlertWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AlertWindow)
{
    QWidget::setWindowFlags(Qt::WindowStaysOnTopHint);
    ui->setupUi(this);
    timer = new QTimer();
    connect(timer, SIGNAL(timeout()), this, SLOT(PlaySound()));
    timer->start(3000);
}

AlertWindow::~AlertWindow()
{
    delete ui;
}

void AlertWindow::on_pushButton_clicked()
{
    timer->stop();
    this->close();
}

void AlertWindow::DisplayAlert(Event A)
{
    ui->label_AlertText->setText(A.description);
    ui->label_AlertDate->setText(A.dateTime.date().toString("yyyy.MM.dd") + " " + A.dateTime.time().toString("hh:mm:ss"));
}

void AlertWindow::PlaySound()
{
    QSound::play("alarm.wav");
}
